
#pragma once
#ifndef __ENCODEDSQLDBACCESS_H__
#define __ENCODEDSQLDBACCESS_H__

#include <QObject>
#include <QSqlDatabase>

class QSqlTableModel;
class QSqlError;


class EncodedSqlDbAccess : public QObject
{
    Q_OBJECT
public:

    explicit EncodedSqlDbAccess(QObject *parent = 0);

    ~EncodedSqlDbAccess();

    const bool isValid() const;
    const bool isEmpty() const;
    const bool isOpen() const;

    inline QSqlDatabase &db() 
    {
        return m_db;
    }

    static const bool exec(
        QSqlQuery &q
    ,   const QString &query);

    static void handleSqlError(const QSqlError &error);

signals:

public slots:
    const bool open(const QString &dbFilePath);

protected:

    const bool initialize(const QString &dbFilePath);
    
    const bool createDb(const QString &dbFilePath);

    const bool openDb(const QString &dbFilePath);
    const bool probeDb() const;

    const bool setupKey(QSqlDatabase &db);

protected:

    bool m_valid;
    bool m_empty;

    QSqlDatabase m_db;
};

#endif // __ENCODEDSQLDBACCESS_H__